﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = "Login";
    }
    protected void BtnLogin_Click(object sender, EventArgs e)
    {
        LblError.Visible = false;
        var userName = TxtUsername.Text;
        var pass = TxtPassword.Text;


        if (string.IsNullOrWhiteSpace(userName) || string.IsNullOrWhiteSpace(pass))
        {
            LblError.Text = "Supply username and password..";
            LblError.Visible = true;
            return;
        }
        PomplingCustomers customer = PomplingCustomers.CustomerSelectByUsername(userName);
        if (string.IsNullOrWhiteSpace(customer.UserName))
        {
            LblError.Text = "username or password incorrect..";
            LblError.Visible = true;
            return;
        }
        if (customer.PomplingPassword != pass)
        {
            LblError.Text = "username or password incorrect..";
            LblError.Visible = true;
            return;
        }

        // TODO: Add a record to a login table..

        customer.RegisterLogin();

        Response.Redirect("admin.aspx?c=" + customer.PomplingCustomerID);
    }
}